/**
 * 学习目标：练习购物车加减
 * 要求：加减按钮，绑定同一个处理函数
 */
import React from 'react';
import ReactDOM from 'react-dom';

class App extends React.Component {
  state = {
    count: 0,
  };

  render() {
    return (
      <div>
        <p>当前数值为：{this.state.count}</p>
        <hr />
        {/* 1. 通过形参接收事件对象 */}
        {/* 2. 如何传递多个参数 */}
        <a onClick={(e) => this.handleClick(1, e)}>+1按钮</a>
        <p>
          <span>{this.state.count}</span>
        </p>

        <a onClick={(e) => this.handleClick(-1, e)}>-1按钮</a>
      </div>
    );
  }

  handleClick = (num, e) => {
    console.log(e, 'handle 打印的event');
    this.setState({
      count: this.state.count + num,
    });
  };
}

ReactDOM.render(<App />, document.getElementById('root'));
